package me.caofeng.controller.manager;

import com.github.pagehelper.PageInfo;
import me.caofeng.annotation.Authentication;
import me.caofeng.enums.OrderStatus;
import me.caofeng.enums.ResponseCode;
import me.caofeng.enums.Role;
import me.caofeng.pojo.Order;
import me.caofeng.pojo.Page;
import me.caofeng.pojo.Response;
import me.caofeng.service.OrderService;
import me.caofeng.service.api.IOrderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.controller.manager
 * @Description:
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-07-03 22:53
 * @Version: V1.0
 */

@Controller
@RequestMapping(value = "manager/order")
@Authentication(role = Role.ADMIN)
public class OrderManagerController {
    private Logger LOGGER = LogManager.getLogger(OrderManagerController.class);

    @Autowired
    private IOrderService orderService;

    @RequestMapping(value = "{page}", method = RequestMethod.GET)
    @ResponseBody
    public Response<Page<List<Order>>> getOrders(
            @PathVariable("page") Integer page,
            @RequestParam(value = "status", defaultValue = "-1") Integer status,
            @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return orderService.getOrders(null, OrderStatus.getStatus(status), Role.ADMIN, page, size);
    }

    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public Response<PageInfo<List<Order>>> getOrdersAsPageInfo(
            @RequestParam(value = "status", defaultValue = "-1") Integer status,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return orderService.getOrdersAsPageInfo(null, OrderStatus.getStatus(status), Role.ADMIN, page, size);
    }

    @RequestMapping(value = "detail/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Response<Order> getOrderDetail(@PathVariable("id") String id) {
        return orderService.getOrderDetail(null, id);
    }

    /**
     * @Author:曹峰 blog.caofeng.me
     * @Date: 2017/7/3 23:46
     * @Description: 发货
     * @param postId 物流单号
     * @param orderId 订单编号
    */
    @RequestMapping(value = "post/{id}",method = RequestMethod.POST)
    @ResponseBody
    public Response sendPost(@PathVariable("id") String orderId ,@RequestParam("postId") String postId ){
        return orderService.sendPost(orderId,postId);
    }
}
